﻿@using Model.WaiGaoQiao;
@model WaiGaoQiaoWeb.Models.AccessPermissionsDistributionVM
@{
    ViewBag.Title = "DeletePermission";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm")
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#chALL").click(function () {
                selectGroup('table1', 'chALL');
            });
            $("#btnCancel").click(function (e) {
                CloseModelWindow(null, false);
            });
            $("#ddldeptName").change(function (e) {
                var vdepid = $("#ddldeptName :selected").val();
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("GetGroupDeptChange")',
                    data: { depid: vdepid },
                    dataType: "json",
                    async: true,
                    success: function (data) {
                        $("#GroupIdDept").empty();
                        var t = $("#GroupIdDept")
                        for (var i in data) {
                            var x = data[i];
                            t.append("<option value='" + x.Value + "'>" + x.Text + "</option>");
                        }
                    },
                    error: function () { }
                });
            });
            $("#btnSave").click(function (event) {
                if (!$("#fmEdit").valid()) {
                    return false;
                }
                if ($("#rightbox")[0].all.length == 0) {
                    showLoadingMsg("请选择要删除权限的员工!", { left: 500, top: 6 }, true, 3000);
                    return false;
                }
                var items = $("input[type='checkbox']");
                $("#rightboxReturn").empty();
                for (var i = 0; i < items.length; i++) {
                    var muid = $(items[i]).attr("name");
                    if (muid != "chALL") {
                        if ($(items[i]).attr("checked")) {
                            for (var v1 = 0; v1 < $("#rightbox")[0].all.length; v1++) {
                                var vPID = $("#rightbox")[0][v1].value;
                                var vPIDName = $("#rightbox")[0][v1].text;
                                $.ajax({
                                    type: "POST",
                                    url: '@Url.Action("BindMenuToRoleEdit")',
                                    data: { mid: muid, EMPNO: vPID, Name: vPIDName },
                                    dataType: "json",
                                    async: false,
                                    success: function (data) {
                                        if (data) {
                                            var t1 = $("#rightboxReturn");
                                            t1.append("<option value='" + 1 + "'>" + data + "</option>");
                                            //t.append("<option value='" + x.Value + "'>" + x.Text + "</option>");
                                        }
                                    },
                                    error: function () { }
                                });
                            }
                        }
                    }
                }
            });
        });
        function select() {
            var vempno = $("#txtEmpNo").val();
            var vpname = $("#txtPName").val();
            var vdeptname = $("#ddldeptName").val();
            var vcardserial = $("#txtCardSerial").val();
            var vGroupIdDept = $("#GroupIdDept").val();
            var vstructrueId = $("#structrueId").val();
            var query = vempno + ',' + vpname + ',' + vdeptname + ',' + vcardserial + ',' + vGroupIdDept + ',' + vstructrueId;
            var rowcount = 0;
            $.ajax({
                type: "POST",
                url: '@Url.Action("GetLeftBox")',
                data: { Select: query },
                dataType: "json",
                async: true,
                success: function (data) {
                    $("#leftbox").empty();
                    var t = $("#leftbox")
                    for (var i in data) {
                        var x = data[i];
                        t.append("<option value='" + x.Value + "'>" + x.Text + "</option>");
                    }
                },
                error: function () { }
            });
        }

        function myRight()//将select框中选中的列，移到另一个select框中
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");

            var count = 0;
            for (i = 0; i < select_b1.length; i++) {
                count = 0;
                if (select_b1.options[i].selected) {
                    var temp = document.createElement("option");
                    temp.value = select_b1[i].value;
                    temp.text = select_b1[i].text;
                    if (select_b2.length == 0) {
                        select_b2.add(temp);
                    }
                    else {
                        for (j = 0; j < select_b2.length; j++) {
                            if (select_b2.options[j].value == temp.value) {
                                count++;
                            }
                        }
                        if (count == 0) {
                            select_b2.add(temp);
                        }

                    }
                }
            }
        }

        function myRightAll()//将select框中选中的列，全部移到另一个select框中
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");
            for (i = select_b2.length; i >= 0; i--) {
                select_b2.remove([i]);
            }
            if (select_b2.length == 0) {
                for (i = 0; i < select_b1.length; i++) {
                    var temp = document.createElement("option");
                    temp.value = select_b1[i].value;
                    temp.text = select_b1[i].text;
                    select_b2.add(temp);
                }
            }
        }

        function myleft()//将select框中选中的列删除
        {
            var select_b2 = document.getElementById("rightbox");
            var tmp = select_b2.length;
            for (i = 0; i < select_b2.length; i++) {
                if (select_b2.options[i].selected) {
                    select_b2.remove([i]);
                    i--;
                }

            }
        }
        function myleftAll()//全部删除将select框中的列
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");
            for (i = select_b2.length; i >= 0; i--) {
                select_b2.remove([i]);
            }
        }
        function selectGroup(div_id, grp_id) {
            var g_div = document.getElementById(div_id);
            var grp = document.getElementById(grp_id);
            var eles = g_div.getElementsByTagName("input");
            for (var i = 0; i < eles.length; i++) {
                if (eles[i].disabled == false) eles[i].checked = grp.checked;
            }
        }
    </script>
}
@using (Html.BeginForm("SavePermissions", "AccessPermissionsDistribution", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.EmpAll)
    <div class="mainpanel">
        <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
            <tr>
                <td style="width: 60%">
                    <table cellpadding="0" cellspacing="6" style="width: 100%; height: auto">
                        <tr>
                            <td colspan="3">
                                人员姓名：@Html.TextBox("txtPName", "", new { @style = "width:90px;" })&nbsp;&nbsp; 人员工号：@Html.TextBox("txtEmpNo", "", new { @style = "width:90px;" })
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
                                    <tr>
                                        <td>
                                            所在部门：@Html.DropDownList("ddldeptName", ViewData["deptName"] as IEnumerable<SelectListItem>,
                                                        new { @style = "width:100px; height:20px; font-size:13px;" })
                                        </td>
                                        <td>
                                            卡号序列：@Html.TextBox("txtCardSerial", "", new { @style = "width:90px;" })
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
                                    <tr>
                                        <td>
                                            所在班组：@Html.DropDownListFor(model => model.GroupIdDept,
                                   ViewData["GroupDept"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:100px; height:22px; font-size:13px;" })
                                        </td>
                                        <td>
                                            所在岗位：@Html.DropDownListFor(model => model.structrueId,
                                            ViewData["StructrueName"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:100px; height:22px; font-size:13px;" })
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <a id="butfind" class="button" href="javascript:void(0);" onclick="select();"><span>
                                    查询</span></a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.ListBoxFor(model => model.leftbox,
                            ViewData["cardleft"] as IEnumerable<SelectListItem>,
                            new { @style = "width:120px; height:250px; font-size:13px;" })
                            </td>
                            <td>
                                <a id="btnRight" href="javascript:void(0);" class="button" onclick="myRight()"><span>
                                    ></span></a><br />
                                <br />
                                <a id="btnLeft" href="javascript:void(0);" class="button" onclick="myleft()"><span><</span></a><br />
                                <br />
                                <a id="btnRightAll" href="javascript:void(0);" class="button" onclick="myRightAll()">
                                    <span>>></span></a><br />
                                <br />
                                <a id="btnLeftAll" href="javascript:void(0);" class="button" onclick="myleftAll()"><span>
                                    <<</span></a>
                            </td>
                            <td>
                                @Html.ListBoxFor(model => model.rightbox,
                            ViewData["cardright"] as IEnumerable<SelectListItem>,
                            new { @style = "width:120px; height:250px; font-size:13px;" })
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 40%">
                    <table cellpadding="0" cellspacing="6" style="width: 100%; height: auto" id="table1">
                        <tr>
                            <td>
                                门禁权限：
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.CheckBoxFor(model => model.chALL)全选/取消
                            </td>
                        </tr>
                        @{
    List<AccessPermissionsDistributionInfo> listmodu = ViewData["allmodular"] as List<AccessPermissionsDistributionInfo>;
    for (int i = 0; i < listmodu.Count; i++)
    {
                            <tr>
                                <td style="text-align: left;">
                                    @Html.CheckBox(listmodu[i].MJId.ToString(), false)<span>@listmodu[i].MJName</span>
                                </td>
                            </tr>
    }
                        }
                        <tr>
                            <td style="height: 120px">
                                @Html.ListBoxFor(model => model.rightboxReturn,
                                ViewData["rightboxReturn"] as IEnumerable<SelectListItem>,
                            new { @style = "width:280px; height:95px; font-size:13px;" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="buttonpanel">
                                    <div style="float: right; margin-right: 10px;">
                                        <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a> <a
                                            id="btnCancel" href="javascript:void(0);" class="button"><span>关闭</span></a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
}
